package com.ruoyi.business.controller;

import com.ruoyi.business.domain.RescueTask;
import com.ruoyi.business.service.IRescueTaskService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 应急救援管理Controller
 *
 * @author bcl
 * @date 2024-09-12
 */
@RestController
@RequestMapping("/rescueTask")
public class RescueTaskController extends BaseController {
    @Autowired
    private IRescueTaskService rescueTaskService;

    /**
     * 查询应急救援管理列表
     */
    @RequiresPermissions("business:rescueTask:list")
    @GetMapping("/list")
    public TableDataInfo list(RescueTask rescueTask) {
        startPage();
        List<RescueTask> list = rescueTaskService.selectRescueTaskList(rescueTask);
        return getDataTable(list);
    }

    /**
     * 导出应急救援管理列表
     */
    @RequiresPermissions("business:rescueTask:export")
    @Log(title = "应急救援管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RescueTask rescueTask) {
        List<RescueTask> list = rescueTaskService.selectRescueTaskList(rescueTask);
        ExcelUtil<RescueTask> util = new ExcelUtil<RescueTask>(RescueTask.class);
        util.exportExcel(response, list, "应急救援管理数据");
    }

    /**
     * 获取应急救援管理详细信息
     */
    @RequiresPermissions("business:rescueTask:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(rescueTaskService.selectRescueTaskById(id));
    }

    /**
     * 新增应急救援管理
     */
    @RequiresPermissions("business:rescueTask:add")
    @Log(title = "应急救援管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RescueTask rescueTask) {
        return toAjax(rescueTaskService.insertRescueTask(rescueTask));
    }

    /**
     * 修改应急救援管理
     */
    @RequiresPermissions("business:rescueTask:edit")
    @Log(title = "应急救援管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RescueTask rescueTask) {
        return toAjax(rescueTaskService.updateRescueTask(rescueTask));
    }

    /**
     * 删除应急救援管理
     */
    @RequiresPermissions("business:rescueTask:remove")
    @Log(title = "应急救援管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(rescueTaskService.deleteRescueTaskByIds(ids));
    }

    @PostMapping("/create")
    public AjaxResult createRescueTask(@RequestBody RescueTask rescueTask) {
        return toAjax(rescueTaskService.createRescueTask(rescueTask));
    }

    @PutMapping("/handle")
    public AjaxResult handleRescueTask(@RequestBody RescueTask rescueTask) {
        return toAjax(rescueTaskService.handleRescueTask(rescueTask));
    }
}
